/*
 * MouseEvents_Simple
 * 
 * PSprite provides a simple API for handling mouse events.
 * Subclasses can override the following PSprite methods
 * to handle mouse events:
 * - mouseClicked()
 * - mouseClickedOutside()
 * - mouseEntered()
 * - mouseExited()
 * - mousePressed()
 * - mousePressedOutside()
 * - mouseReleased()
 * - mouseReleasedOutside()
 * - mouseDown()
 * - mouseUp()
 * - mouseDragged()
 * - mouseMoved()
 * 
 * A PSprite instance will only receive mouse events if it is
 * currently on the display list, so be sure to addChild() it
 * to PSpriteContainer or to an other PSprite that is already
 * on the display list before attempting to handle mouse events.
 * 
 * Many mouse events are only handled if they are within the bounds
 * of the PSprite instance.  See the MouseEvents_Bounds example for
 * a more in-depth explanation of PSprite.bounds().
 */

import com.transmote.psg.*;
import com.transmote.psg.events.*;

PSpriteContainer spriteContainer;

void setup () {
  size(400, 400);
  setupSprites();
}

void draw () {
  background(0);
  spriteContainer.update();
}

void setupSprites () {
  // create a PSpriteContainer to hold all other PSprites
  spriteContainer = new PSpriteContainer(this);
  
  // attach ButtonSprite instances to the SpriteContainer
  ButtonSprite spriteLeft = new ButtonSprite();
  spriteLeft.x = 50;
  spriteLeft.y = 150;
  spriteContainer.addChild(spriteLeft);
  ButtonSprite spriteRight = new ButtonSprite();
  spriteRight.x = 250;
  spriteRight.y = 150;
  spriteContainer.addChild(spriteRight);
  
  // set each ButtonSprite up to handle
  // events generated by the other ButtonSprite
  spriteLeft.addObserver(spriteRight);
  spriteRight.addObserver(spriteLeft);
}
